package org.canx.repository;

import org.canx.domain.Token;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

import javax.transaction.Transactional;
import java.sql.Timestamp;

/**
 * Created by weican on 2017/7/27.
 */
public interface TokenRepository extends PagingAndSortingRepository<Token, String> {
    Token findByUserNameAndToken(String userName, String token);

    Token findByToken(String token);

    @Transactional
    @Modifying
    @Query("update Token g set g.expiredTime = :expiredTime where g.token = :token")
    public void updateExpiredTime(@Param("token") String token, @Param("expiredTime") Timestamp expiredTime);
}
